package cn.ouryears.system.dao.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.jdbc.core.PreparedStatementSetter;

import cn.ouryears.common.datasource.BaseDAO;
import cn.ouryears.system.bean.OperLogBean;
import cn.ouryears.system.dao.IOperLogDAO;

public class OperLogDAOImpl extends BaseDAO implements IOperLogDAO {

	/** 
	 * insert operlog by using spring jdbctemplate preparestatement
	 */
	@Override
	public void insert(final OperLogBean log) {
		StringBuffer sql = new StringBuffer();
		
		sql.append("insert into oper_log(request_url,request_ip,request_time,response_time,exception_msg,ext_a,ext_b) ");
		sql.append("values(?,?,?,?,?,?,?)");
		
		getJdbcTemplate().update(sql.toString(), new PreparedStatementSetter(){
			@Override
			public void setValues(PreparedStatement ps) throws SQLException {
				ps.setString(1, log.getRequestUrl());
				ps.setString(2, log.getRequestIp());
				ps.setDate(3, log.getRequestTime());
				ps.setDate(4, log.getResponeTime());
				ps.setString(5, log.getExceptionMsg());
				ps.setString(6, log.getExtA());
				ps.setString(7, log.getExtB());
			}
		});
	}
	

}
